﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Linq.Mapping;
using ECI.Entities;
using ECI.Entities.Builder;

namespace ECI.LIP.Entities
{
    ///<summary>
    ///[MES_BOX_MATERIAL]
    ///</summary>
    [Serializable]
    [Table(Name = "MES_BOX_MATERIAL")]
    public partial class MesBoxMaterial
    {
        ///<summary>
        ///[箱号]
        ///</summary>
        [Column(Storage = "BOX_NO")]
        public string BoxNo { get { return this._BoxNo; } set { this._BoxNo = value; if (this.DataModelBegin)AddEnum(MesBoxMaterialEnum.BoxNo); } }
        ///<summary>
        ///[材料编号]
        ///</summary>
        [Column(Storage = "MATERIAL_NO")]
        public string MaterialNo { get { return this._MaterialNo; } set { this._MaterialNo = value; if (this.DataModelBegin)AddEnum(MesBoxMaterialEnum.MaterialNo); } }
        ///<summary>
        ///[创建人]
        ///</summary>
        [Column(Storage = "CRATE_USER")]
        public string CrateUser { get { return this._CrateUser; } set { this._CrateUser = value; if (this.DataModelBegin)AddEnum(MesBoxMaterialEnum.CrateUser); } }
        ///<summary>
        ///[创建日期]
        ///</summary>
        [Column(Storage = "CREATE_DATE")]
        public System.Nullable<System.DateTime> CreateDate { get { return this._CreateDate; } set { this._CreateDate = value; if (this.DataModelBegin)AddEnum(MesBoxMaterialEnum.CreateDate); } }

        /// <summary>
        /// ????????:???????True?,????????,?????????????????????,???????????????????????????????????
        /// </summary>
        public void StartSetSQLValue()
        {
            this.DataModelBegin = true;
        }

        /// <summary>
        /// ???????
        /// </summary>
        public void EndSetSQLValue()
        {
            this.DataModelBegin = false;
        }

        private bool DataModelBegin;
        public List<MesBoxMaterialEnum> ListEnum { get; set; }

        public void AddEnum(MesBoxMaterialEnum item)
        {
            if (ListEnum == null) ListEnum = new List<MesBoxMaterialEnum>();
            if (!ListEnum.Contains(item))
            {
                ListEnum.Add(item);
            }
        }



        private MesBoxMaterialEnum _keyField;
        public MesBoxMaterialEnum KeyField { get { return this._keyField; } }

        public void SetKeyField(MesBoxMaterialEnum keyField)
        {
            this.HasSetKeyField = true;
            this._keyField = keyField;
        }

        public MesBoxMaterial()
        {
        }

        public MesBoxMaterial(MesBoxMaterialEnum keyField)
        {
            this.HasSetKeyField = true;
            this._keyField = keyField;
        }

        public bool HasSetKeyField { get; set; }

        public MesBoxMaterialEnum SortByField { get; set; }

        public SortDirection SortDirection { get; set; }


        public string SQLUpdate
        {
            get { return new SQLBuilder<MesBoxMaterial, MesBoxMaterialEnum>().Update(this); }
        }

        public string SQLInsert
        {
            get { return new SQLBuilder<MesBoxMaterial, MesBoxMaterialEnum>().Insert(this); }
        }

        public string SQLDelete
        {
            get { return new SQLBuilder<MesBoxMaterial, MesBoxMaterialEnum>().Delete(this); }
        }

        public string SQLSelect
        {
            get { return new SQLBuilder<MesBoxMaterial, MesBoxMaterialEnum>().Select(this); }
        }

        public void SetAllEnum()
        {
            new SQLBuilder<MesBoxMaterial, MesBoxMaterialEnum>().SetAllEnum(this);
        }

        private DataTable FetchDataTable()
        {
            return FetchDataTable(null);
        }

        private DataTable FetchDataTable(object ts)
        {
            return new ECI.Entities.Builder.EntityBuilder<MesBoxMaterial, MesBoxMaterialEnum>().GetDataTable(this, ts);
        }

        /// <summary>
        /// ???????????????????FetchEntity??????
        /// </summary>
        public bool HasFetchData { get; set; }

        /// <summary>
        /// ??????????????????????FetchEntity??????
        /// </summary>
        public bool NotFetchData { get { return !HasFetchData; } }

        /// <summary>
        /// ??????-???????SQL
        /// </summary>
        /// <returns>???:???????????????????????? ??????????????HasFetchData??????</returns>
        public MesBoxMaterial FetchEntity()
        {
            return FetchEntity("", null);
        }

        /// <summary>
        /// ??????-???SQL???
        /// </summary>
        /// <param name="sql">??????</param>
        /// <returns>???:???????????????????????? ??????????????HasFetchData??????</returns>
        public MesBoxMaterial FetchEntity(string sql)
        {
            return FetchEntity(sql, null);
        }

        /// <summary>
        /// ??????-???????SQL
        /// </summary>
        /// <param name="ts">????</param>
        /// <returns>???:???????????????????????? ??????????????HasFetchData??????</returns>
        public MesBoxMaterial FetchEntity(object ts)
        {
            return FetchEntity("", ts);
        }

        /// <summary>
        /// ??????-???SQL???
        /// </summary>
        /// <param name="sql">??????</param>
        /// <param name="ts">????</param>
        /// <returns>???:???????????????????????? ??????????????HasFetchData??????</returns>
        public MesBoxMaterial FetchEntity(string sql, object ts)
        {
            return new ECI.Entities.Builder.EntityBuilder<MesBoxMaterial, MesBoxMaterialEnum>().GetEntity(sql, this, ts);
        }

        /// <summary>
        /// ?????????-???????SQL
        /// </summary>
        /// <returns>??????</returns>
        public List<MesBoxMaterial> FetchEntities()
        {
            return FetchEntities("", null);
        }

        /// <summary>
        ///  ?????????-???SQL???
        /// </summary>
        /// <param name="sql">??????</param>
        /// <returns>??????</returns>		
        public List<MesBoxMaterial> FetchEntities(string sql)
        {
            return FetchEntities(sql, null);
        }

        /// <summary>
        /// ?????????-???????SQL
        /// </summary>
        /// <param name="ts">????</param>
        /// <returns>??????</returns>
        public List<MesBoxMaterial> FetchEntities(object ts)
        {
            return FetchEntities("", ts);
        }

        /// <summary>
        ///  ?????????-???SQL???
        /// </summary>
        /// <param name="sql">??????</param>
        /// <param name="ts">????</param>
        /// <returns>??????</returns>
        public List<MesBoxMaterial> FetchEntities(string sql, object ts)
        {
            return new ECI.Entities.Builder.EntityBuilder<MesBoxMaterial, MesBoxMaterialEnum>().GetEntities(sql, this, ts);
        }

        /// <summary>
        /// ?????????????
        /// </summary>
        /// <returns>True???? False??????</returns>
        public bool Exists()
        {
            return Exists(null);
        }

        /// <summary>
        ///  ?????????????
        /// </summary>
        /// <param name="ts">????</param>
        /// <returns>True???? False??????</returns>
        public bool Exists(object ts)
        {
            MesBoxMaterial item = this.FetchEntity(ts);
            return item.HasFetchData;
        }




    }


    public partial class MesBoxMaterial
    {
        private string _BoxNo = "";
        private string _MaterialNo = "";
        private string _CrateUser = "";
        private System.Nullable<System.DateTime> _CreateDate;
    }


    public enum MesBoxMaterialEnum
    {
        ///<summary>
        ///[箱号]
        ///</summary>
        BoxNo,
        ///<summary>
        ///[材料编号]
        ///</summary>
        MaterialNo,
        ///<summary>
        ///[创建人]
        ///</summary>
        CrateUser,
        ///<summary>
        ///[创建日期]
        ///</summary>
        CreateDate
    }
}
